package com.zyzd.retrofit.base;


import java.util.ArrayList;
import java.util.List;

/**
 * Created by lzy on 2018/5/3 0003.
 * description ${列表Presenter 基类}
 */

public abstract class BaseRecyclerPresenter<V extends BaseRecyclerContract.IView, T> extends BasePresenter<V> implements BaseRecyclerContract.IPresenter<V, T> {
    protected int mPageIndex = getDefaultPageIndex();

    @Override
    public void onRefresh() {
        mPageIndex = getDefaultPageIndex();
        mView.setEnableLoadMore(mView.isEnableLoadMore());
        loadData(true);
    }

    @Override
    public void onLoadMore() {
        loadData(false);
    }

    @Override
    public void onLoadDataSuccess(boolean isRefresh, List<T> data) {
        if (data == null) data = new ArrayList<>();
        mPageIndex++;
        mView.onLoadDataSuccess(isRefresh, data);
        mView.setEnableLoadMore(mView.isEnableLoadMore() && data.size() >= getPageSize());
    }

    @Override
    public void onLoadDataFail(boolean isRefresh, String msg) {
        mView.onLoadDataFail(isRefresh, msg);
    }

    @Override
    public int getPageSize() {
        return 15;
    }

    @Override
    public int getDefaultPageIndex() {
        return 0;
    }



}
